#!/usr/bin/env python3
"""
悬浮窗启动脚本

启动MixVideo悬浮窗，提供快速访问功能
"""

import sys
import os
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from src.gui.modern_gui.floating_window import floating_manager
from src.gui.modern_gui.themes import ModernTheme
import argparse


def main():
    """主函数"""
    parser = argparse.ArgumentParser(description="MixVideo 悬浮窗")
    parser.add_argument(
        "--type",
        choices=["full", "mini", "logo"],
        default="logo",
        help="悬浮窗类型: full(完整版), mini(迷你版) 或 logo(仅Logo)"
    )
    parser.add_argument(
        "--width", 
        type=int, 
        default=300,
        help="窗口宽度 (仅适用于完整版)"
    )
    parser.add_argument(
        "--height", 
        type=int, 
        default=500,
        help="窗口高度 (仅适用于完整版)"
    )
    parser.add_argument(
        "--opacity", 
        type=float, 
        default=0.95,
        help="窗口透明度 (0.1-1.0)"
    )
    parser.add_argument(
        "--always-on-top",
        action="store_true",
        default=True,
        help="窗口始终置顶"
    )
    parser.add_argument(
        "--use-emoji",
        action="store_true",
        default=False,
        help="使用emoji作为Logo（需要系统支持）"
    )
    parser.add_argument(
        "--light-theme",
        action="store_true",
        default=False,
        help="使用浅色主题（默认为深色主题）"
    )
    
    args = parser.parse_args()
    
    # 设置主题
    ModernTheme.setup_theme()
    
    try:
        # 主题配置
        dark_theme = not args.light_theme
        theme_name = "浅色" if args.light_theme else "深色"

        if args.type == "logo":
            # 创建Logo悬浮窗
            emoji_status = "emoji" if args.use_emoji else "文字"
            print(f"启动Logo悬浮窗（{emoji_status}模式，{theme_name}主题）...")
            window = floating_manager.create_logo_window(use_emoji=args.use_emoji, dark_theme=dark_theme)
        elif args.type == "mini":
            # 创建迷你悬浮窗（实际上也是Logo悬浮窗）
            emoji_status = "emoji" if args.use_emoji else "文字"
            print(f"启动迷你悬浮窗（{emoji_status}模式，{theme_name}主题）...")
            window = floating_manager.create_mini_window(use_emoji=args.use_emoji, dark_theme=dark_theme)
        else:
            # 创建完整悬浮窗
            print("启动完整悬浮窗...")
            window = floating_manager.create_floating_window(
                width=args.width,
                height=args.height,
                always_on_top=args.always_on_top
            )

            # 设置透明度
            if 0.1 <= args.opacity <= 1.0:
                window.attributes("-alpha", args.opacity)
        
        print(f"悬浮窗已启动 (类型: {args.type})")
        print("使用 Ctrl+C 或关闭按钮退出")

        # 运行主循环
        window.mainloop()
        
    except KeyboardInterrupt:
        print("\n正在关闭悬浮窗...")
        floating_manager.close_all_windows()
    except Exception as e:
        print(f"启动悬浮窗时出错: {e}")
        sys.exit(1)


if __name__ == "__main__":
    main()
